package tools

import (
	"bufio"
	"fmt"
	"io"
	"net/http"
)

type FileTools struct {
}

var FileToolsObject FileTools

func (f FileTools) ReadFile(fileName string) (readString string, err error) {
	v, err := http.Get(fileName)
	if nil != err {
		return
	}
	// 创建文件的读取器
	file := v.Body
	reader := bufio.NewReader(file)
	// 死循环读取
	for {
		// 以换行符为界，分批次读取数据，得到readString
		readString, e := reader.ReadString('\n')
		if e != nil && e != io.EOF {
			fmt.Println("文件读取失败;err", e)
			// 如果已到文件末尾，则直接结束
			break
		}
		return readString, nil
	}
	return
}
